//
//  LCCheckView.m
//  YiJun
//
//  Created by Rochang on 2017/4/23.
//  Copyright © 2017年 Rochang. All rights reserved.
//

#import "LCCheckView.h"

@interface LCCheckView ()

@property (weak, nonatomic) IBOutlet UIView *maskView;
@property (weak, nonatomic) IBOutlet UIView *tipView;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;


@end

@implementation LCCheckView
- (void)awakeFromNib {
    [super awakeFromNib];
    self.tipView.layer.cornerRadius = 5;
    self.tipView.clipsToBounds = YES;
}

- (IBAction)close:(id)sender {
    [self hideWithAnimation:YES];
}

+ (instancetype)shareInstance {
    static LCCheckView *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].firstObject;
    });
    return _instance;
}

- (void)showWithTitle:(NSString *)title result:(NSString *)result {
    self.titleLabel.text = title;
    self.resultLabel.text = result;
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.frame = [UIScreen mainScreen].bounds;
    self.tipView.alpha = 0;
    self.alpha = 0;
    self.tipView.transform = CGAffineTransformMakeScale(0.1, 0.1);
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.tipView.alpha = 1.0;
        weakSelf.alpha = 1.0;
        weakSelf.tipView.transform = CGAffineTransformIdentity;
    }];
}

- (void)hideWithAnimation:(BOOL)animtaion {
    if (!animtaion) {
        [self removeFromSuperview];
        return;
    }
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.tipView.alpha = 0;
        weakSelf.alpha = 0;
        weakSelf.tipView.transform = CGAffineTransformMakeScale(0.1, 0.1);
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
}
@end
